from flask import Blueprint, request, jsonify, current_app
import logging, os
from utils import common
products_bp = Blueprint('products', __name__, url_prefix='/product')


@products_bp.route('/list', methods=['GET'])
def product_list():
    data =  current_app.config['DB'].get_product_list()

    keys = ['name','price','discount','days','calls','img_calls','enabled','sales','sort_num']
    rv = list()
    for item in data:
        rv.append(
            {key:value for key,value in zip(keys, item)}
        )
    return jsonify({'code':0, 'data':rv})

@products_bp.record
def log(app):
    logging.info('register products blueprint')
